<template>
  <span @click="copy" class="copy">
    <slot></slot>
  </span>
</template>
<script>
import { Toast } from 'vant';
export default {
  name: 'CopyText',
  props: {
    text: { default: "" }
  },
  methods:{
    copy(){
      let text = this.text;
      let save = (e) => {
          e.clipboardData.setData('text/plain', text);//clipboardData对象
          e.preventDefault();//阻止默认行为
      };
      document.addEventListener('copy', save);
      document.execCommand("copy");
      Toast.success('已复制')
    }
  }
}
</script>
<style scoped>
.copy{
  display: inherit;
}
</style>
